/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
private:
    vector<string> rst;
public:
    vector<string> binaryTreePaths(TreeNode* root) {
        binaryTreePathsStep(root, "");
        return rst;
    }

    void binaryTreePathsStep(TreeNode* root, string path) {
        if(root == nullptr) return;

        path = path + to_string(root->val);

        if(root->left == nullptr && root->right == nullptr) rst.push_back(path);
        if(root->left || root->right) path = path + "->";
        if(root->left) binaryTreePathsStep(root->left, path);
        if(root->right) binaryTreePathsStep(root->right, path);
    }
};